/*
 * 项目名称:    wms-server-jeecg
 * 创建人员:    FanZhiwen
 * 创建时间:    2023-10-10
 */
package org.jeecg.modules.flow.callback.inbound.task;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.business.warehouse.entity.WmsInReceiptTask;
import org.jeecg.modules.business.warehouse.mapper.WmsInReceiptTaskMapper;
import org.jeecg.modules.flow.callback.enums.DocumentStatusEnum;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 入库任务关闭bean
 *
 * @author FanZhiwen
 * @version 1.0.0
 * @since 2023-10-10
 */
@Component
@Slf4j
public class WmsInReceiptCloseBeforeBean<T> extends BaseCustomBeanRun<T> {
    @Resource
    private WmsInReceiptTaskMapper wmsInReceiptTaskMapper;

    @Override
    public void actureRun() {
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        // 获取请求参数
        baseFlowDto.translateClass(JSONObject.class);
        String taskId = baseFlowDto.getInfoId();
        WmsInReceiptTask task = wmsInReceiptTaskMapper.selectById(taskId);
        if (ObjectUtil.isEmpty(task)) {
            throw new JeecgBootException("入库任务不存在!");
        }
//        if (!task.getDocumentStatus().equals("2") || task.getWarehouseStatus().equals("3")) {
//            throw new JeecgBootException("该任务不可关闭!");
//        }
        task.setDocumentStatus(DocumentStatusEnum.CLOSE.getCode());
        wmsInReceiptTaskMapper.updateById(task);
        // 当前前端调用业务需要你返回的
        baseFlowDto.setResult(Result.OK());
        // id是保存业务记录的id。用于生成业务流程信息记录
        baseFlowDto.setInfoId(taskId);
    }
}
